Skip to content

improve SQL queries for predicates on main-table columns#556

Open
cportele wants to merge 1 commit into
masterfrom
inline-main-table-predicates
Open

improve SQL queries for predicates on main-table columns#556
cportele wants to merge 1 commit into
masterfrom
inline-main-table-predicates

Conversation

@cportele

Copy link
Copy Markdown
Contributor

A filter predicate on a scalar column of the main feature table was always encoded as a self-semi-join (A.id IN (SELECT A.id FROM <main> WHERE ...)). That subquery scans the whole table and the planner does not flatten it, so its cost grew with the table size rather than with the number of selected features. Such predicates are now emitted as a direct conjunct on the main alias. The semi-join form is kept whenever evaluating the predicate requires a join, junction, or array traversal, where it is load-bearing for cardinality.

This also fixes a latent bug in the temporal interval (OVERLAPS) encoding, which hardcoded a trailing parenthesis to close the self-semi-join subquery; it now preserves the operand expression's suffix so both the inline and the subquery forms stay balanced. A negated inline predicate is wrapped as NOT (...).

Updates the golden SQL specs and query fixtures accordingly.

A filter predicate on a scalar column of the main feature table was always
encoded as a self-semi-join (A.id IN (SELECT A.id FROM <main> WHERE ...)).
That subquery scans the whole table and the planner does not flatten it, so
its cost grew with the table size rather than with the number of selected
features. Such predicates are now emitted as a direct conjunct on the main
alias. The semi-join form is kept whenever evaluating the predicate requires
a join, junction, or array traversal, where it is load-bearing for
cardinality.

This also fixes a latent bug in the temporal interval (OVERLAPS) encoding,
which hardcoded a trailing parenthesis to close the self-semi-join subquery;
it now preserves the operand expression's suffix so both the inline and the
subquery forms stay balanced. A negated inline predicate is wrapped as
NOT (...).

Updates the golden SQL specs and query fixtures accordingly.
@cportele cportele requested a review from azahnen as a code owner June 29, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant